package com.example.qrcode.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.qrcode.entity.Product;

import com.example.qrcode.vo.ProductVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Param;

@Mapper
public interface ProductMapper extends BaseMapper<Product> {

    @Select("SELECT p.*, pd.* " +
            "FROM product p " +
            "LEFT JOIN product_detail pd ON p.product_s_no = pd.product_s_no " +
            "WHERE p.product_s_no = #{productSNo}")
    ProductVO selectProductWithDetail(String productSNo);



    @Select("SELECT device_id FROM product_detail WHERE product_s_no = #{productSNo}")
    String getDeviceIdByProductSNo(String productSNo);

    IPage<ProductVO> getProductsWithDetail(Page<ProductVO> page);

    @Select("SELECT line_num FROM product_detail WHERE product_s_no = #{productSNo}")
    Integer getLineNumByProductSNo(@Param("productSNo") String productSNo);
}
